<?php
class interestController extends appController {
    
    public function generalLearning($id=null,$sub_cat=null){
        $meta_val = serialize($sub_cat);
        if($_SERVER["REQUEST_METHOD"]=='POST'){
                      // echo "<pre>"; print_r($_POST);exit;
                $id = $this->_model->updateInterest($id, INTEREST_GENERAL, $meta_val);
                
                if($id !== false){
                    header('Location: generalLearning');
                    exit;
                }
            
                                
        }

        $getSubCats = $this->_model->getSubCats();
        $getInterest = $this->_model->getInterest(INTEREST_GENERAL);
        $this->view->set('getSubCats',$getSubCats);
        $this->view->set('getInterest',$getInterest[0]);
        return $this->view();
    }
    public function reindex(){
        
        
        $data = $this->_model->read(); 
                
        header('Content-Type: application/json; charset=utf-8');
        //echo "ok";
        $this->view->set('items',$data);
        return $this->view();
        
    }

        public function underGraduation( $id=null, $meta_key,$mytext, $university_name=null, $course_name=null, $year=null, $sem_name=null){

        if($_SERVER["REQUEST_METHOD"]=='POST'){
            $err = array();
            
            if($mytext == ""){
                $err[] = "Subject Name are Required !";
            }
            
            if($university_name == ""){

               $err[] = "Add University Name !";
            }
            
            if($course_name == ""){
                $err[] = "Add Course !";
            }
            
            if($year == ""){
                $err[] = "Add year !";
            }
            
            if($sem_name == ""){
                $err[] = "Add semester !";
            }

                if(!$err){
                $meta_val = array("mytext"=>$mytext, "university_name"=>$university_name, "course_name"=>$course_name, "year"=>$year, "sem_name"=>$sem_name);
                $meta_val = serialize($meta_val);
                $id = $this->_model->updateInterest($id, INTEREST_UNDER_GRADUATION, $meta_val);
                
                if($id !== false){
                    header('Location: underGraduation');
                    exit;
                }
            }
            else{
                $this->view->set('err',$err);
            }
                                
        }

       
        $undergradute = $this->_model->getInterest(INTEREST_UNDER_GRADUATION);
        $this->view->set('undergradute',$undergradute[0]);
        $getyears = $this->_model->getyears();
        $this->view->set('getyears',$getyears);
        $getsemesters = $this->_model->getsemesters();
        $this->view->set('getsemesters',$getsemesters);
        return $this->view();
    }
    public function underGrade($id=null, $school_board = null, $school_name = null, $class = null, $sem_name = null, $name = null){
        if($_SERVER["REQUEST_METHOD"]=='POST'){
            $error = array();
            // if($school_board=="")
            // {
            //     $error[] =  "Add School Board Name !";
            // }
            // if($school_name=="")
            // {
            //     $error[] =  "Add School Name !";
            // }
            // if($class=="")
            // {
            //     $error[] =  "Class Name Add !";
            // }
            // if($sem_name=="")
            // {
            //     $error[] =  "Add Semester Name !";
            // }
            
            if(count($error) == 0){
                $meta_val = array("school_board"=>$school_board, "school_name"=>$school_name, "class"=>$class, "sem_name"=>$sem_name, "name"=>$name);
                
                $meta_val = serialize($meta_val);
                // echo $id;exit();
                $id = $this->_model->updateInterest($id, INTEREST_UNDER_GRADE, $meta_val);
                    
                if($id !== false){
                    header('Location: underGrade');
                    exit;
                }
            }
            else
            {
             $this->view->set('error',$error);   
            }
            
                                
        }
        $underGrade = $this->_model->getInterest(INTEREST_UNDER_GRADE);
        // print_r($underGrade);exit;
        $this->view->set('underGrade',$underGrade[0]);
        $getSubjects = $this->_model->getSubjects();
        $this->view->set('getSubjects',$getSubjects);
        $getsemesters = $this->_model->getsemesters();
        $this->view->set('getsemesters',$getsemesters);
        $getClasses = $this->_model->getClasses();
        $this->view->set('getClasses',$getClasses);
        return $this->view();
    }
    public function masters($id=null, $course_name = null, $year = null, $sem_name, $mytext = null){
        if($_SERVER["REQUEST_METHOD"]=='POST'){
            $error = array();
            // if ($course_name == "") {
            //     $error[] = "Add Course Name !";
            // }
            // if ($year == "") {
            //     $error[] = "Select Year";
            // }
            // if ($sem_name == "") {
            //     $error[] = "Select semester Name !";
            // }
            if(count($error) == 0){
            $meta_val = array("course_name"=>$course_name, "year"=>$year, "sem_name"=>$sem_name, "mytext"=>$mytext);
            
            $meta_val = serialize($meta_val);
                $id = $this->_model->updateInterest($id, INTEREST_MASTERS, $meta_val);
                                       
                if($id !== false){
                    header('Location: masters');
                    exit;
                }
            }else
            {
                $this->view->set('error',$error);    
            }
                                
        }
        $masters = $this->_model->getInterest(INTEREST_MASTERS);
    // print_r($masters);
        $this->view->set('masters',$masters[0]);
        $getyears = $this->_model->getyears();
        $this->view->set('getyears',$getyears);
        $getsemesters = $this->_model->getsemesters();
        $this->view->set('getsemesters',$getsemesters);
        return $this->view();
    }
    }
    
